package com.quanquan.store.repository;

import com.quanquan.store.entity.Commercial;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @ClassName:CommercialRepository
 * @Description:TODO
 * @Author:xiongjunbao
 * @Date:2019/3/12 10:40
 * @Version 1.0
 */
public interface CommercialRepository extends JpaRepository<Commercial, String> {

    /**
     * 查找有效的业态列表
     *
     * @return
     */
    @Query(value = "SELECT * FROM oo_commercial WHERE status_show = 0 AND status_remove = 0 ORDER BY sort_order ASC", nativeQuery = true)
    List<Commercial> list();

    /**
     * 通过name查找业态信息
     *
     * @param name
     * @return
     */
    @Query(value = "SELECT * FROM oo_commercial WHERE status_show = 0 AND status_remove = 0 AND name = ?1", nativeQuery = true)
    Commercial findByNameAndAndStatusRemoveAndAndStatusShow(String name);


    /**
     * 通过name查找业态信息
     *
     * @param id
     * @return
     */
    @Query(value = "SELECT * FROM oo_commercial WHERE status_show = 0 AND status_remove = 0 AND id = ?1", nativeQuery = true)
    Commercial findByIdAndAndStatusRemoveAndAndStatusShow(String id);

    /**
     * 通过name查找业态信息
     *
     * @param id
     * @return
     */
    @Query(value = "SELECT * FROM oo_commercial WHERE status_remove = 0 AND id = ?1", nativeQuery = true)
    Commercial findByCommercialId(String id);

}
